package com.hymjweb.demo.hymj.native_bill_manage.other_charges.service;

import com.hymjweb.demo.framework.sys.BaseService;
import com.hymjweb.demo.framework.util.DataTypeUtil;
import com.hymjweb.demo.hymj.native_bill_manage.other_charges.bean.BNativeBillOtherCharges;
import com.hymjweb.demo.hymj.native_bill_manage.other_charges.mapper.BNativeBillOtherChargesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BNativeBillOtherChargesService extends BaseService {

    @Autowired
    private BNativeBillOtherChargesMapper bNativeBillOtherChargesMapper;

    /**
     * 批量插入分单其他费用列中的数据
     * @param otherCharges
     * @return
     */
    @Transactional(rollbackFor = {Exception.class})
    public int batchInsert(List<BNativeBillOtherCharges> otherCharges) throws Exception {
        if(otherCharges==null || otherCharges.isEmpty()){
            throwException("批量添加分单其他费用参数错误!");
        }
        int effectRows = bNativeBillOtherChargesMapper.batchInsert(otherCharges);

        return effectRows;
    }

    /**
     * 根据分单号查询分单其他费用列表
     * @param billId
     * @return
     */
    public List<BNativeBillOtherCharges> getOtherChargesListByBillId(String billId) throws Exception {
        if(DataTypeUtil.isEmptyStr(billId)){
            throwException("根据分单号检索分单其他费用列表参数错误!");
        }
        List<BNativeBillOtherCharges> otherChargesList = bNativeBillOtherChargesMapper.getListByBillId(billId);
        return otherChargesList;
    }

    /**
     * 根据分单id删除分单其他费用列表
     * @param billId
     * @return
     */
    @Transactional(rollbackFor = {Exception.class})
    public int deleteByBillId(String billId) throws Exception {
        if(DataTypeUtil.isEmptyStr(billId)){
            throwException("根据分单号删除分单其他费用参数错误!");
        }
        return bNativeBillOtherChargesMapper.deleteByBillId(billId);
    }

    @Transactional(rollbackFor = {Exception.class})
    public int delete(String id) throws Exception {
        if(DataTypeUtil.isEmptyStr(id)){
            throwException("删除分单其他费用参数错误!");
        }
        return bNativeBillOtherChargesMapper.deleteById(id);
    }
}
